home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-10-02 | 3.4 KB | 168 lines | [TEXT/MPS ] |
- Unit CursorWrap;
-
- Interface
-
- Uses
- {$LOAD MAC.Dump}
- MemTypes,QuickDraw,OSIntf,Toolintf,PackIntf,Script;
-
- Procedure SetUpVBL;
- Procedure Wrap;
-
- Implementation
-
- Procedure SetUpVBL;
-
- var
- theVBL : VBLTask;
- myQElem : QElemPtr;
- myErr : OSErr;
- SaveZone : THz;
- SizeNeeded : Longint;
- PatchPtr : Ptr;
- theCode : Handle;
- thePtr : ^LongInt;
- dummyErr : OSErr;
-
- Begin
- { * Get handle to our code *}
- theCode:=Get1Resource('INIT',1);
-
- { * Use the system's Heap * }
- SaveZone:=GetZone;
- SetZone(SystemZone);
-
- { * Get size of our patch code and our QElem ptr * }
- SizeNeeded:=SizeResource(theCode)-(LongInt(@SetUpVBL)-LongInt(theCode^))+sizeof(QElem);
- ResrvMem(SizeNeeded);
- If MemError<>NoErr then
- begin
- { * If not enouph room in system heap then get out * }
- SysBeep(1);
- SetZone(SaveZone);
- exit(SetUpVBL);
- end;
-
- { * Get new ptr for our code * }
- PatchPtr:=NewPtr(SizeNeeded+4);
-
- { * blockmove our code in * }
- BlockMove(@Wrap,Pointer(Ord(PatchPtr)+4),SizeNeeded);
-
- { * get new ptr for our VBL task * }
- myQElem:=QElemPtr(NewPtr(sizeof(QElem)));
-
- { * restore zone * }
- SetZone(SaveZone);
-
- { * put our vbl task ptr's address into the ptr where our patch code will be * }
- thePtr:=Pointer(PatchPtr);
- thePtr^:=LongInt(myQElem);
-
- { * set up VBL and install * }
- with theVBL do
- begin
- qType:=Ord(vType);
- vblAddr:=Pointer(Ord(PatchPtr)+4);
- vblCount:=6;
- vblPhase:=0;
- end;
- myQElem^.vblQElem:=theVBL;
-
- dummyErr:=VInstall(myQElem);
- End;
- {-----------------------------------------------------------------------------}
- Procedure Wrap;
-
- {
- **
-
- This code allows the cursor to seemly wrap around the screen when the
- <Option> key is held down.
-
- **
- }
-
- const
- CurrentA5 = $904;
-
- var
- myQElem : QElemPtr;
- thePtr : ^LongInt;
- CursorCoordPtr : ^Point;
- ChangedPtr : ^Byte;
- changed : Boolean;
- theMap : KeyMap;
- currGDevice : GDHandle;
- myRectPtr : ^Rect;
- myPtr,myPtr2 : ^longint;
- mouseRect : Rect;
-
- Begin
- { * Get the keymap and check if option down; if is not then do not allow wrap * }
- GetKeys(theMap);
- If theMap[58] then
- Begin
- { * set up ptr to low memory global of cursor location * }
- CursorCoordPtr:=Pointer($828);
- changed:=false;
-
- { * get rectangle of screen * }
- currGDevice:=GetGDevice;
- If currGDevice<>Nil
- then
- mouseRect:=currGDevice^^.gdRect
- else
- begin
- myPtr:=pointer(CurrentA5);
- myPtr2:=pointer(myPtr^);
- myRectPtr:=Pointer(myPtr2^-116);
-
- mouseRect:=myRectPtr^;
- end;
- InsetRect(mouseRect,1,1);
-
- { * check cursor location and change it if wrapping * }
- With CursorCoordPtr^,mouseRect do
- Begin
- if v<=top then
- Begin
- v:=bottom-1;
- changed:=true;
- End
- else if v>=bottom then
- Begin
- v:=top+1;
- changed:=true;
- End;
-
- if h<=left then
- Begin
- h:=right-1;
- changed:=true;
- End
- else if h>=right then
- Begin
- h:=left+1;
- changed:=true;
- End;
- End;
-
- { * if we changed the cursor location then set the low memory global cursorNew * }
- If changed then
- Begin
- changedPtr:=Pointer($8CE);
- { * this tells the cursor drawing routines that the cursor is moved * }
- changedPtr^:=$FF;
- End;
- End;
-
- { * get ptr to VBL taks from where we originally put it * }
- thePtr:=Pointer(Ord(@Wrap)-4);
-
- { * reset the vblcount so that we are executed again * }
- myQElem:=QElemPtr(thePtr^);
- myQElem^.vblQElem.vblCount:=6;
- End;
-
- End.